﻿#include "SongList.h"
#include<qmutex.h>

SongList::SongList(QObject *parent)
	: QObject(parent)
{}

//SongList& SongList::getInstance()
//{
//	// TODO: 在此处插入 return 语句
//	static SongList list;
//	return list;
//}

void SongList::appendSafe(const Song& s)
{
	{
		QMutexLocker<QMutex> locker(&m_mutex);
		m_songList.push_back(s);
	}
	emit SongAppended(s);
}

void SongList::appendSafe(const QList<Song>& s_list)
{
	{
		QMutexLocker<QMutex> locker(&m_mutex);
		m_songList.append(s_list);
	}
	emit SongAppended(s_list);
}

void SongList::remove(int index)
{
	QMutexLocker<QMutex> locker(&m_mutex);
	m_songList.remove(index);
}

//QList<Song>& SongList::getSongList()
//{
//	// TODO: 在此处插入 return 语句
//	return m_songList;
//}


int SongList::size()
{
	QMutexLocker<QMutex> locker(&m_mutex);
	return m_songList.size();
}

Song& SongList::operator[](int index)
{
	// TODO: 在此处插入 return 语句
	QMutexLocker<QMutex> locker(&m_mutex);
	return m_songList[index];
}

QUrl SongList::getSongUrl(int index)
{
	QMutexLocker<QMutex> locker(&m_mutex);
	return m_songList[index].url;
}

SongList::~SongList()
{

}
